Attribute VB_Name = "modODBCAllSeating"
'---------------------------------------------------------------------------------------
'Module     : modODBC
'Date       : 05/18/2004
'Updated    : 02/21/2005
'Author     : Chris Elwell
'Purpose    : This is an example of a CIC integration module. This is for demostration
'           purposes only. You must write the code required to get/writeback data from/to
'           your customer's data source.
'
'           This example uses the FSMSClientTest.mdb. A DSN is setup as FSMSClientTest.
'           Regardless of the integration method, CICs must have a module that contains
'           specific sub routines. All of these subs/functions listed below must exist
'           as they are called from the main program.
'           Public Function GetData(ByVal strKey As String) As Boolean - this routine is
'               called when the Order ID field loses focus. This is where you would code to
'               get order data from a customer and populate the screen fields. You can create
'               and call as many support routines as necessary. Also, this routine should
'               return a boolean True if getting the order data was succesful and a boolean
'               False if it was not.
'           Public Sub WriteReply() - this is called after a successful shipment. A typical
'               use would be to write FXRS reply data back to a customer's system, but can be
'               used for anything that you want to have happen after a pckage is shipped.
'           Public Sub WriteError() - this is called after an error is returned from FXRS.
'           Public Sub WriteDelete(ByVal strTracking As String) - this is called after a
'               package is successfully deleted.
'           Public Sub AfterClose() - this is called after FXRS is closed.
'           Public Sub BeforeClose() - this is called just before an FXRS close transaction
'               is sent.
'Updated:   Public Function BeforeShip() - Return TRUE to continue shipment, False to cancel.
'           Public Sub Initialize() - this is called once on program execution.
'           Public Sub BeforeBatch() - this is called before processing a batch file.
'           Public Sub BeforeBatchShip() - this is called before each individual batch transaction.
'New:       Public Sub AfterAddrLookup() - this is called after cboCustID, cboContact, and cboCompany lose focus
'New:       Public Sub AfterDeptLostFocus() - this is called after cboDept or f38 loses focus.
'
' 2005-04-20, JFW, Added AddDSN for integration database.
' 2006-11-07, JFW, Add order to MPS select to preserve package order
' 2007-04-13, JFW, Allow for custom screen display, AfterConnect
' 2007-05-23, JFW, CTI intetration for Mike.
'
'---------------------------------------------------------------------------------------


' See Project properties for Conditional Compilation
#If AllSeating Then

Option Explicit

Dim m_CNIn As ADODB.Connection
Dim m_CNInA As ADODB.Connection
Dim m_CNIn9 As ADODB.Connection
Dim strCNIn As String

'Dim m_CNOut As ADODB.Connection
Dim m_RSCustomer As ADODB.Recordset
Dim m_RS As ADODB.Recordset
Dim m_strLine As String
Dim m_strKeyValue As String

'2/8/05 - API function declaration to add DSN to system used in AddDSN() function.
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal _
   hwndParent As Long, ByVal fRequest As Long, ByVal _
   lpszDriver As String, ByVal lpszAttributes As String) As Long

'+
' 2006-09-20, JFW, From Copernicus FXI
' Declare object(s)
Public g_strCustNo As String        'Hold Customer Number
Public g_strPONo As String          'Hold Customer PO Number
Public g_strRefNo As String         'Hold Customer Reference Number
Public g_strCountry As String       'Hold shipto Country
Public g_strZip As String           'Holds zip code
Public g_strEmail As String         'Hold Email address
Public g_strEmail2 As String        'Hold Email address
Public g_blnServiceOrder As Boolean 'Flage for email
'~


'---------------------------------------------------------------------------------------
' Procedure : AddDSN
' DateTime  : 2/8/2005
' Purpose   : Adds the FSMSClient v720.3 DSN
' Call from : Form_Load
'---------------------------------------------------------------------------------------
'
Private Function AddDSN() As Boolean
    On Error GoTo EH

    Dim ret As Long
    Dim Driver As String
    Dim Attributes As String

    If GetSystemName = "WINXPC9CA96EA3" Then
        Driver = "Microsoft Access Driver (*.mdb)"
        Attributes = Attributes & "DBQ=C:\Documents and Settings\563774\My Documents\FXI\Projects\Linda\AllSeating.mdb" & Chr(0)
        Attributes = Attributes & "DSN=FedExAllSeating" & Chr(0)
        Attributes = Attributes & "DESCRIPTION=FSMS Client All Seating ship data" & Chr(0)

        ret = SQLConfigDataSource(0, 4, Driver, Attributes)
        If ret <> 1 Then
            AddDSN = False
        Else
            AddDSN = True
        End If

    Else
        ' 2007-05-23, JFW, no autodefine, DSN=FEDEX;UID=sa;PWD=sa
        AddDSN = True
    End If

    Exit Function
EH:
    AddDSN = False

End Function
'

Public Function ClearCommodity() As Boolean

End Function
'

Public Function ClearShipScreen() As Boolean

    m_strKeyValue = ""

End Function

'---------------------------------------------------------------------------------------
' Procedure : GetData()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetData(ByVal strKey As String) As Boolean
    On Local Error GoTo Handler
    Dim strSelect As String
    Dim strUserPwd As String    'DSN user and password separated by ','
    Dim strUser As String       'DSN user name
    Dim strPwd As String        'DSN user password
    Dim strData As String
    Dim i As Long

'    If g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Writeback" _
'    And g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Order Lookup" Then
'        GetData = True
'        Exit Function
'    End If

    m_strKeyValue = strKey

    strSelect = "select * from SorMaster where SalesOrder = '" & strKey & "' order by 1"

    If Not Connect Then Exit Function   'set conection and recordset

    m_RS.CursorLocation = adUseClient
    m_RS.Open strSelect, m_CNIn, adOpenStatic     'run SELECT
    If m_RS.BOF And m_RS.EOF Then
        m_RS.Close
        If strCNIn = "9" Then
            Set m_CNIn = m_CNInA
            strCNIn = "A"
        Else
            Set m_CNIn = m_CNIn9
            strCNIn = "9"
        End If
        m_RS.Open strSelect, m_CNIn, adOpenStatic     'run SELECT
        If m_RS.BOF And m_RS.EOF Then
            m_RS.Close
            GetData = False
            Exit Function
        End If
    End If

    strSelect = "select * from ArCustomer where Customer = '" & m_RS!CUSTOMER & "' order by 1"

    m_RSCustomer.CursorLocation = adUseClient
    m_RSCustomer.Open strSelect, m_CNIn, adOpenStatic     'run SELECT



    'Example use of SetCurrentAccount to programmatically change the current shipping account
'    If Not SetCurrentAccount(m_rs!AcctNum) Then
'        MsgBox "Account not found. Please select account from Location box", vbExclamation, "Error"
'    End If

    Call DeleteIntlCommodities(strKey)

    If m_RS.BOF Or m_RS.EOF Then
        strData = "No records"
    Else
        For i = 0 To m_RS.Fields.Count - 1
            strData = strData & vbCrLf & m_RS.Fields(i).name & " " & m_RS.Fields(i).Value
        Next i
    End If

    strData = "Record count " & m_RS.RecordCount & vbCrLf & strData

    Call GetDataToShip

    ' Example use of the SetMessage sub
    ' Call SetMessage("Destination state is: " & m_rs!State, 16, vbBlack, True)

    frmShip.f1670.SetFocus

    GetData = True
Release:
    ' call kill
    Exit Function
Handler:
    MsgBox Err.Description, , "modODBC.GetData"
    Call Kill
    Resume Release
    Resume

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : GetData()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Sub GetDataToShip()

    On Local Error GoTo Handler

    Dim strZipCode As String
    Dim intZipLen As Integer
    Dim lngWeight As Double
    Dim strHarmCode As String
    Dim strMyHarmCode As String
    Dim strCCofMan  As String
    Dim strTaxID As String
    Dim i As Long, j As Long
    Dim strAddressLine As String
    Dim strPhone As String
    Dim rsZip As New ADODB.Recordset
    Dim strSoldTo As String

'    ' Declare variables for procedure
'    Dim i As Long
'    Dim blnADDComm As Boolean
'    Dim strCommCode As String
'    Dim strSQLComm As String
'    Dim strMeter As String

    With frmShip

        g_strErrorLocation = "Country"
        strZipCode = Trim(m_RS!ShipPostalCode & "")
        strZipCode = Replace(strZipCode, " ", "")
        strZipCode = Replace(strZipCode, "-", "")
        If IsNumeric(strZipCode) Then
            g_strCountry = "US"
        Else
            g_strCountry = "CA"
        End If
        .f50.Text = g_strCountry
        DoEvents
        .f17.Text = strZipCode
        DoEvents

        If g_strCountry = "US" Then
            .f1482.Value = 1
        Else
            .f1482.Value = 0
        End If

        '        g_strErrorLocation = "AccountSwitch"
        '        If True Or False Then
        '        If GetSystemName <> "CAN00278478" Then
        '            If g_strCountry = "US" Then
        '                If Not SetCurrentAccount("224037961") Then
        '                    MsgBox "Unable to switch to US account 224037961.  Please select account from Location box", vbExclamation, "Error"
        '                End If
        '            Else
        '                If Not SetCurrentAccount("221737920") Then
        '                    MsgBox "Unable to switch to account 221737920.  Please select account from Location box", vbExclamation, "Error"
        '                End If
        '            End If
        '        End If
        '        End If

        If g_strCountry = "US" Then
            rsZip.Open "select * from ZipCityState where PostalCode = '" & Left(strZipCode, 5) & "' " _
                            & "and Country = '" & g_strCountry & "' " _
                            & "order by 1,2,3" _
                , g_connFSMSClient
        Else
            For i = 0 To (Len(strZipCode) - 1)
                If rsZip.State > 0 Then rsZip.Close
                rsZip.Open "select * from ZipCityState where PostalCode = '" & Left(strZipCode, Len(strZipCode) - i) & "' " _
                                & "and Country = '" & g_strCountry & "' " _
                                & "order by 1,2,3" _
                    , g_connFSMSClient
                If Not rsZip.BOF Then
                    Exit For
                End If
            Next i
        End If
        If Not rsZip.BOF Then
            ' State
            .f16.Text = Trim(rsZip!ProvinceCode & "")
            ' City
            Do
                If rsZip.EOF Then Exit Do
                If .f15.Text & "" = "" Then
                    .f15.Text = Trim(rsZip!CityName & "")
                Else
                    If .f15.Text & "" <> rsZip!CityName & "" Then
                        .f15.Text = ""
                        Exit Do
                    End If
                End If
                rsZip.MoveNext
            Loop
        End If

        .f11.Text = Trim(m_RS!CustomerName & "")

        For i = 1 To 5
            strAddressLine = Trim(m_RS.Fields("ShipAddress" & CStr(i)) & "")

            If Left(strAddressLine, 3) = "^SI" Then strAddressLine = ""

            ' Address 1
            If strAddressLine <> "" Then
                If .f13.Text & "" = "" Then
                    If IsNumeric(Left(strAddressLine, 1)) Then
                        .f13.Text = strAddressLine
                        strAddressLine = ""
                    End If
                End If
            End If
            ' Contact f12
            If strAddressLine <> "" Then
                If .f12.Text & "" = "" Then
                    If Left(UCase(strAddressLine), 5) = "ATTN:" Then
                        strAddressLine = Replace(strAddressLine, "attn:", "")
                        strAddressLine = Replace(strAddressLine, "ATTN:", "")
                        strAddressLine = Trim(strAddressLine)
                        .f12.Text = strAddressLine
                        strAddressLine = ""
                    End If
                End If
            End If
            ' Phone f18
            If strAddressLine <> "" Then
                If .f18.Text & "" = "" Then
                    strPhone = UCase(strAddressLine)
                    strPhone = Replace(strPhone, "PH", "")
                    strPhone = Replace(strPhone, "CBD", "")
                    strPhone = Replace(strPhone, ":", "")
                    strPhone = Replace(strPhone, "-", "")
                    strPhone = Replace(strPhone, "(", "")
                    strPhone = Replace(strPhone, ")", "")
                    strPhone = Replace(strPhone, " ", "")
                    If IsNumeric(strPhone) Then
                        If Len(strPhone) = 11 Then strPhone = Right(strPhone, 10)
                        .f18.Text = strPhone
                        strAddressLine = ""
                    End If
                End If
            End If

            ' City, State
            If 0 <> InStr(1, strAddressLine, ",") Then
                j = UBound(Split(strAddressLine, ","))
                If Len(Trim(Split(strAddressLine, ",")(j))) = 2 Then
                    If .f16.Text & "" = "" Then
                        .f16.Text = Split(strAddressLine, ",")(j)
                    End If
                    If .f15.Text & "" = "" Then
                        .f15.Text = Split(strAddressLine, ",")(0)
                    End If
                    strAddressLine = ""
                End If
            End If

            ' Contact or address 2
            If strAddressLine <> "" Then
                If .f14.Text & "" = "" Then
                    .f14.Text = strAddressLine
                    strAddressLine = ""
                End If
            End If
            If strAddressLine <> "" Then
                If .f12.Text & "" = "" Then
                    .f12.Text = strAddressLine
                    strAddressLine = ""
                End If
            End If

        Next i

        ' Must have phone number
        If .f18.Text & "" = "" Then
            .f18.Text = "9055027200"
        End If

        .f3056.Text = Trim(m_RS!CustomerPoNumber & "")

        .f1273 = "01"
        .f1670 = 1
        .f116 = 1
        .f1274 = "92"
        .f23 = 1
        .f70 = 1
        .f72 = 1
        
        'debugprint "1090 " & .f1090.Text
        If Left(.f50.Text, 2) = "CA" Then
            .f68.Text = "CAD"
            .f1090.Text = "CAD"
        ElseIf Left(.f50.Text, 2) = "US" Then
            If .f68.Text = "" Then
                .f68.Text = "USD"
            End If
            If .f1090.Text = "" Then
                .f1090.Text = "USD"
            End If
        Else
            If .f68.Text = "" Then
                .f68.Text = "CAD"
            End If
            If .f1090.Text = "" Then
                .f1090.Text = "CAD"
            End If
        End If
        'debugprint "1090 " & .f1090.Text
        
        .f25.Text = Trim(CStr(m_RS!SalesOrder & ""))
        .f1358.Text = Trim(CStr(m_RS!CompanyTaxNo & ""))
        If .f1358.Text = "" Then
            .f1358.Text = Trim(CStr(m_RS!GstExemptNum & ""))
        End If

        If Not m_RSCustomer.BOF And Not m_RSCustomer.EOF Then
            strZipCode = Trim(m_RSCustomer!SoldPostalCode & "")
            strZipCode = Replace(strZipCode, " ", "")
            strZipCode = Replace(strZipCode, "-", "")
            If strZipCode <> "" And .f17.Text <> strZipCode Then
                If Trim(m_RSCustomer!Contact & "") <> "" Then
                    strSoldTo = strSoldTo & IIf(strSoldTo <> "", ", ", "") & Trim(m_RSCustomer!Contact & "")
                End If
                If Trim(m_RSCustomer!name & "") <> "" Then
                    strSoldTo = strSoldTo & IIf(strSoldTo <> "", ", ", "") & Trim(m_RSCustomer!name & "")
                End If
                If Trim(m_RSCustomer!SoldToAddr1 & "") <> "" Then
                    strSoldTo = strSoldTo & IIf(strSoldTo <> "", ", ", "") & Trim(m_RSCustomer!SoldToAddr1 & "")
                End If
                If Trim(m_RSCustomer!SoldToAddr2 & "") <> "" Then
                    strSoldTo = strSoldTo & IIf(strSoldTo <> "", ", ", "") & Trim(m_RSCustomer!SoldToAddr2 & "")
                End If
                If Trim(m_RSCustomer!SoldToAddr3 & "") <> "" Then
                    strSoldTo = strSoldTo & IIf(strSoldTo <> "", ", ", "") & Trim(m_RSCustomer!SoldToAddr3 & "")
                End If
                If Trim(m_RSCustomer!SoldToAddr4 & "") <> "" Then
                    strSoldTo = strSoldTo & IIf(strSoldTo <> "", ", ", "") & Trim(m_RSCustomer!SoldToAddr4 & "")
                End If
                If Trim(m_RSCustomer!SoldPostalCode & "") <> "" Then
                    strSoldTo = strSoldTo & IIf(strSoldTo <> "", ", ", "") & Trim(m_RSCustomer!SoldPostalCode & "")
                End If
                If Trim(m_RSCustomer!Telephone & "") <> "" Then
                    strSoldTo = strSoldTo & IIf(strSoldTo <> "", ", ", "") & Trim(m_RSCustomer!Telephone & "")
                End If

                If strSoldTo <> "" Then
                    Call InsertIntlCommodities(.f1.Text, 0, "SoldTo: " & strSoldTo, "CA", "", 1, "", "", "EA", "0.000001", "0.01", "SOLDTO", "")
                End If

                If .f1358.Text = "" Then
                    .f1358.Text = Trim(CStr(m_RS!GstExemptNum & ""))
                End If

            End If
        End If

        For i = 1 To 5
            If UCase(Trim(m_RS.Fields("ShipAddress" & i).Value & "")) = UCase(.f15.Text & ", " & Left(.f16.Text, 2)) Then
                frmShip.StatusBar1.Panels(2) = "City and State confirmed OK."
                Exit For
            End If
        Next i
        If i >= 6 Then
            MsgBox "Address confirmation (city, state):" & vbCrLf _
                & vbCrLf _
                & Trim(m_RS.Fields("ShipAddress1").Value & "") & IIf(Trim(m_RS.Fields("ShipAddress1").Value & "") <> "", vbCrLf, "") _
                & Trim(m_RS.Fields("ShipAddress2").Value & "") & IIf(Trim(m_RS.Fields("ShipAddress2").Value & "") <> "", vbCrLf, "") _
                & Trim(m_RS.Fields("ShipAddress3").Value & "") & IIf(Trim(m_RS.Fields("ShipAddress3").Value & "") <> "", vbCrLf, "") _
                & Trim(m_RS.Fields("ShipAddress4").Value & "") & IIf(Trim(m_RS.Fields("ShipAddress4").Value & "") <> "", vbCrLf, "") _
                & Trim(m_RS.Fields("ShipAddress5").Value & "") & IIf(Trim(m_RS.Fields("ShipAddress5").Value & "") <> "", vbCrLf, "") _
                & vbCrLf _
                & .f15.Text & ", " & .f16.Text & vbCrLf
        End If
    End With

    g_strErrorLocation = "Done"
Release:
    ' call kill
    Exit Sub
Handler:
    MsgBox "Error at " & g_strErrorLocation & " - " & Err.Description, , "modODBC.GetDataToShip"
    Call Kill
    Resume Release
    Resume

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteReply()
' DateTime  : 2/14/2005
' Purpose   : REQUIRED SUB. Called after a successful ship transaction.
'             This example shows how to obtain multiple occurrence fields from the
'             FXRS reply and how to obtain multiple occurrence fields included in the
'             input transaction but not returned in the FXRS reply.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReply()

    On Local Error GoTo Handler

    Dim intCount As Long
    Dim strSelect As String

'    If g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Writeback" Then
'        Exit Sub
'    End If

    If m_strKeyValue <> "" Then
        strSelect = "update SorMaster set SpecialInstrs = '" & g_str29 & "' where SalesOrder = '" & m_strKeyValue & "'"

        If Not Connect Then Exit Sub   'set conection and recordset

        m_CNIn.Execute strSelect, intCount
    End If

    m_strKeyValue = ""

    'debugprint "WriteReply", intCount

Release:
    Exit Sub

Handler:
    MsgBox "Error at " & g_strErrorLocation & " - " & Err.Description, , "modODBC.WriteReply"
    Call Kill
    Resume Release

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteError()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an FXRS Error reply transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteError()
    MsgBox "Shipping Error: " & g_str3, vbCritical, "FSMS Error"
End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteDelete()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             successful FXRS Delete.
'---------------------------------------------------------------------------------------
'
Public Sub WriteDelete(ByVal strTracking As String)
'Called:    frmShip Parsecomplete event on FSMS 123 reply
'Purpose:   update customer table on void
    On Local Error GoTo Handler

    Dim intCount As Long
    Dim rs As New ADODB.Recordset
    Dim strSelect As String

'    If g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Writeback" Then
'        Exit Sub
'    End If

    rs.Open "select * from Shipments where g_str29 = '" & strTracking & "'", g_connFSMSClient
    If rs.BOF Then
        rs.Close
        rs.Open "select * from TD where g_str29 = '" & strTracking & "'", g_connFSMSClient
    End If

    If Not rs.BOF Then
        strSelect = "update SorMaster set SpecialInstrs = '' where SalesOrder = '" & rs!g_str25 & "' and SpecialInstrs = '" & strTracking & "'"

        If Not Connect Then Exit Sub        'set conection and recordset

        m_CNInA.Execute strSelect, intCount
        m_CNIn9.Execute strSelect, intCount

        'debugprint "WriteDelete", intCount
    End If

Release:
   ' call kill
   Exit Sub
Handler:
    MsgBox Err.Description, , "modODBC.WriteDelete"
    Call Kill
    Resume Release

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : Connect()
' DateTime  : 7/5/2004
' Purpose   : Open connection to ODBC test DSN. Instantiate module level recordset.
'---------------------------------------------------------------------------------------
'
Private Function Connect() As Boolean
    On Local Error GoTo Handler
    Dim strDSN As String
    Dim boolSecondTry As Boolean

    If m_CNInA Is Nothing Then
        Set m_CNInA = New ADODB.Connection
    End If
    If m_CNIn9 Is Nothing Then
        Set m_CNIn9 = New ADODB.Connection
    End If
    'If m_CNOut Is Nothing Then
    '    Set m_CNOut = New ADODB.Connection
    'End If
    Set m_RS = New ADODB.Recordset
    Set m_RSCustomer = New ADODB.Recordset

    If m_CNInA.State <> adStateOpen Then   'if connection is not open then do so
        If GetSystemName = "WINXPC9CA96EA3" Then
            Call AddDSN
            m_CNInA.Open "DSN=FedExAllSeating"
        Else
            m_CNInA.Open "DSN=FedExImport;UID=sa;PWD=dgd150f"
        End If
        Set m_CNIn = m_CNInA
        strCNIn = "A"
    End If
    If m_CNIn9.State <> adStateOpen Then   'if connection is not open then do so
        If GetSystemName = "WINXPC9CA96EA3" Then
            Call AddDSN
            m_CNIn9.Open "DSN=FedExAllSeating"
        Else
            m_CNIn9.Open "DSN=FedExImport;UID=sa;PWD=dgd150f;Database=SysproCompany9"
        End If
    End If
    'Set m_CNOut = m_CNIn
    Connect = True

    Exit Function

Handler:
    If Not boolSecondTry Then
        boolSecondTry = True
        If Err.number = -2147467259 Then
            Call AddDSN
            Resume
        End If
    End If
    MsgBox Err.Description, , "modODBC.Connect"
    Call Kill        'kill connection and recordset

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : Kill()
' DateTime  : 7/5/2004
' Purpose   : Close connection and recordset objects and set = to nothing.
'---------------------------------------------------------------------------------------
'
Public Sub Kill()
    On Local Error GoTo Handler

    If Not m_RS Is Nothing Then
        If m_RS.State = adStateOpen Then m_RS.Close
    End If
    If Not m_RSCustomer Is Nothing Then
        If m_RSCustomer.State = adStateOpen Then m_RSCustomer.Close
    End If
    If Not m_CNInA Is Nothing Then
        If m_CNInA.State = adStateOpen Then m_CNInA.Close
    End If
    If Not m_CNIn9 Is Nothing Then
        If m_CNIn9.State = adStateOpen Then m_CNIn9.Close
    End If

    Set m_CNIn = Nothing      'kill connection
    Set m_CNInA = Nothing      'kill connection
    Set m_CNIn9 = Nothing      'kill connection
    Set m_RS = Nothing      'kill recordset
    Set m_RSCustomer = Nothing

    'If Not m_CNOut Is Nothing Then
    '    If m_CNOut.State = adStateOpen Then m_CNOut.Close
    'End If
    'Set m_CNOut = Nothing      'kill connection

    Exit Sub
Handler:
    MsgBox Err.Description, , "modODBC.Kill"

End Sub
'


'---------------------------------------------------------------------------------------
' Procedure : AfterAddrVerify()
' DateTime  : 5/12/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             Address Verification. Three possible status codes are passed. See comments
'             below.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerify(ByVal intStatusCode As Integer)

    Select Case intStatusCode
        'Address is verfified
        Case 1

        'Soft error
        Case 2

        'Hard error
        Case 3

    End Select

End Sub

'---------------------------------------------------------------------------------------
' Procedure : AfterAddrVerifyUpdate()
' DateTime  : 9/13/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an address has been updated on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerifyUpdate()

End Sub


'---------------------------------------------------------------------------------------
' Procedure : AfterBatchShip()
' DateTime  : 10/28/2005
' Purpose   : REQUIRED SUB. Called just after a batch transaction has been processed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatchShip()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterBatch()
' DateTime  : 4/6/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             a batch shipment has been completed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatch()

End Sub


'---------------------------------------------------------------------------------------
' Procedure : AfterClose()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Sub AfterClose()

End Sub
'

' 2007-04-13, JFW, Allow for custom screen display.
Public Sub AfterConnect()

    ' For Manulife, go to customer lookup
    ' Call frmShip.ToggleLookup(True)

End Sub


'---------------------------------------------------------------------------------------
' Procedure : AfterLocationChange()
' DateTime  : 3/06/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             the shipping Location has been changed on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterLocationChange()

    g_strErrorLocation = "ODBCAllSeating.AfterLocationChange.In"
    With frmShip
        If .cboLocationName(0).Text = "ALLSEATING" Then
            If Left(.f50.Text, 2) <> "US" Then
                .f50.Text = "US"
                DoEvents
                If g_strTDMasterTrkNbr <> "" Then
                    .f1482.Value = 1
                End If
                DoEvents
            End If
        End If
    End With
    g_strErrorLocation = "ODBCAllSeating.AfterLocationChange.Out"

End Sub



'---------------------------------------------------------------------------------------
' Procedure : AfterLostFocus()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboDept or f38 loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterLostFocus(c1 As Control)

    If c1.name = "f38" Then
        'g_clsReg.SetRegistryValue "Carry_f38", frmShip.f38, REG_SZ
    End If
    If c1.name = "f1273" Then
        'g_clsReg.SetRegistryValue "Carry_f1273", Left(frmShip.f1273.Text, 2), REG_SZ
    End If

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterRateQuote()
' DateTime  : 20071106-01
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             a rate quote.
'---------------------------------------------------------------------------------------
'
Public Sub AfterRateQuote()

End Sub

'---------------------------------------------------------------------------------------
' Procedure : BeforeClose()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed before
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Function BeforeClose() As Boolean

    BeforeClose = True

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeShip()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED Function. Modified to Return Boolean which controls whether or not
'             the shipment will continue or be canceled. Return True to continue shipment,
'             False to cancel.
'---------------------------------------------------------------------------------------
'
Public Function BeforeShip(Optional TransString As String = "") As Boolean

    Dim objRetVal As VbMsgBoxResult

    With frmShip
        If Left(.f50.Text, 2) <> "CA" Then
            If Not IsNumeric(Trim(.txtTotCustVal)) Then
                objRetVal = MsgBox("This " & IIf(.f1482.Value = 1, "TD", "Intl") & " shipment has no customs value.  Please return and correct.")
            ElseIf CDbl(Trim(.txtTotCustVal)) <= 0 Then
                objRetVal = MsgBox("This " & IIf(.f1482.Value = 1, "TD", "Intl") & " shipment has no customs value.  Please return and correct.")
            ElseIf CDbl(Trim(.txtTotCustVal)) < 1 Then
                objRetVal = MsgBox("This " & IIf(.f1482.Value = 1, "TD", "Intl") & " shipment requires $1 minimum customs value.  Please return and correct.")

'            ElseIf CDbl(Trim(.txtTotCustVal)) <= 1 Then
'                objRetVal = MsgBox("This " & IIf(.f1482.Value = 1, "TD", "Intl") & " shipment has little customs value.  OK or cancel to return and correct.", vbOKCancel + vbDefaultButton2)
'                If objRetVal = vbOK Then
'                    BeforeShip = True
'                End If
            
            Else
                BeforeShip = True
            End If
        Else
            BeforeShip = True
        End If
        If .f38.Text = "" Then
            frmMsgBox.ShowMessage "Department is required.", 2000
            DoEvents
            If .SSTab1.Tab <> 0 Then
                .SSTab1.Tab = 0
                DoEvents
            End If
            .f38.SetFocus
            DoEvents
            BeforeShip = False
        End If
    End With

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeShipTrans()
' DateTime  : 8/7/2008
' Purpose   : REQUIRED Function. Modified to Return Boolean which controls whether or not
'             the shipment will continue or be canceled. Return True to continue shipment,
'             False to cancel.
'---------------------------------------------------------------------------------------
'
Public Function BeforeShipTrans(ByRef TransString As String) As Boolean
    
    Dim lngMsgBoxResult As VbMsgBoxResult
    BeforeShipTrans = True
    
End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BuildCustomSPLabel()
' DateTime  : 20070620-04
' Purpose   : REQUIRED SUB. Can be used as hook to create custom EPL or ZPL buffer labels
'             for SmartPost.
'---------------------------------------------------------------------------------------
'
Public Function BuildCustomSPLabel(ByVal strLabel As String) As String

    BuildCustomSPLabel = strLabel

End Function


Public Sub EditBoxLostFocus(objControl As Control)

End Sub


'---------------------------------------------------------------------------------------
' Procedure : Initialize()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed on
'             program execution.
'---------------------------------------------------------------------------------------
'
Public Sub Initialize(Optional f1 As Form)

'    g_strErrorLocation = "ODBCAllSeating.Initialize.In"
'    DoEvents
'
'    With frmShip
'        If .cboLocationName(0).Text = "ALLSEATING" Then
'            If Left(.f50.Text, 2) <> "US" Then
'                .f50.Text = "US"
'                DoEvents
'                If g_strTDMasterTrkNbr <> "" Then
'                    .f1482.Value = 1
'                End If
'                DoEvents
'            End If
'        End If
'    End With
'    g_strErrorLocation = "ODBCAllSeating.Initialize.Out"

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeBatch()
' DateTime  : 8/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed on
'             program execution. Called before an entire batch is processed.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatch() As Boolean

    BeforeBatch = True

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeBatchShip()
' DateTime  : 8/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed on
'             program execution. Called just before a batch transaction is sent to the server.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatchShip() As Boolean

    BeforeBatchShip = True

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : AfterAddrLookup()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboCustID, cboContact, or cboCompany loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrLookup()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterDeptLostFocus()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboDept or f38 loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterDeptLostFocus()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : GetPickupData()
' DateTime  : 1/30/2006
' Purpose   : REQUIRED SUB. Called from frmAddTags.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetPickupData(ByVal strKey As String) As Boolean

    GetPickupData = True

End Function


'---------------------------------------------------------------------------------------
' Procedure : WriteBatchEditReply()
' DateTime  : 1/17/2006
' Purpose   : REQUIRED SUB. Called after a successful Batch Error Edit transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBatchEditReply()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteTagReply()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteCancelTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Cancel Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteCancelTagReply()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteReturnDelete()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label delete transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnDelete(ByVal strTracking As String)

End Sub

'---------------------------------------------------------------------------------------
' Procedure : WriteReturnReply()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnReply()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteBOLReply()
' DateTime  : 1/11/2006
' Purpose   : REQUIRED SUB. Called after a successful FedEx Freight BOL transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBOLReply()

End Sub

#End If

